import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'

Vue.use(VueRouter)

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

//引入文件中的某个对象
import { get_token } from '@/utils/auth'

import { check_login } from '@/api/login'

import nProgress from 'nprogress'

router.beforeEach((to,from,next) => {

  nProgress.start();
  if(!to.meta.not_check){
    if(!get_token()){
      next('login');
      return;
    }
    check_login({}).then((res) => {
      console.log(res, "::::");
    });
  }
  next();
});

router.afterEach(()=>{
 nProgress.done();
});

//暴露整个文件
export default router

